﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Enter.Common;
using Enter.Entity;
using Enter.BizLogic;
using Enter.Config;

namespace Enter.Web.SystemAdmin.GoodClass
{
    public partial class importClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int p = 1; p < 13; p++)
            {


                string pacode = GetCode("", p);
                string content = FileHelper.readFile("G:\\项目\\网上商城\\Code\\Enter.Web.SystemAdmin\\txt\\" + pacode + ".txt", "GB2312");

                string[] str1 = content.Replace("\r\n", "").Replace("\t", "").Split('】');
                for (int i = 1; i <= str1.Length; i++)
                {
                    string a = str1[i - 1];
                    string code1 = GetCode(pacode, i);
                    string[] str3 = a.Split('|');
                    string name1 = str3[0];
                    save(code1, name1, pacode);
                    if (str3[1].Contains("；"))
                    {
                        string[] str4 = str3[1].Split('；');
                        for (int j = 1; j <= str4.Length; j++)
                        {
                            string b = str4[j - 1];
                            string[] str5 = b.Split('：');
                            string name3 = str5[0];
                            string code3 = GetCode(code1, j);
                            save(code3, name3, code1);
                            if (str5.Length != 1)
                            {

                                if (str5[1].Contains("*"))
                                {
                                    string[] str6 = str5[1].Split('*');
                                    for (int l = 1; l <= str6.Length; l++)
                                    {
                                        string c = str6[l - 1];
                                        string[] str7 = c.Split('，');
                                        string name4 = str7[0];
                                        string code4 = GetCode(code3, l);
                                        save(code4, name4, code3);
                                        if (str7.Length != 1)
                                        {
                                            string[] str8 = str7[1].Split('、');
                                            for (int k = 1; k <= str8.Length; k++)
                                            {
                                                string name5 = str8[k - 1];
                                                string code5 = GetCode(code4, k);
                                                save(code5, name5, code4);
                                            }
                                        }

                                    }
                                }
                                else
                                {
                                    string[] str6 = str5[1].Split('、');
                                    for (int k = 1; k <= str6.Length; k++)
                                    {
                                        string name4 = str6[k - 1];
                                        string code4 = GetCode(code3, k);
                                        save(code4, name4, code3);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        string[] str4 = str3[1].Split('、');
                        for (int k = 1; k <= str4.Length; k++)
                        {
                            string name3 = str4[k - 1];
                            string code3 = GetCode(code1, k);
                            save(code3, name3, code1);
                        }
                    }
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            //string filepath= FileHelper.GetFileMapPath("txt\\"+FileUpload1.FileName);;
            //FileUpload1.SaveAs(filepath);
            //string ss =
          
        }
        private string GetCode(string pcode, int num)
        {
            if (num < 10)
            {
                return pcode+"0" + num.ToString();
            }
            return pcode+num.ToString();
        }

        private void save(string code, string name, string ParentID)
        {
            T105_GoodClassEntity model = new T105_GoodClassEntity();
            T105_GoodClassBLLSub bll = new T105_GoodClassBLLSub();

            model.CNO = code;
            model.CName = name.Trim();

            model.Weight = 0;
            model.ParentID = ParentID;
            model.Status = EnumStatus.Valid;

            bll.Save(model);
        }

    }
}